//
//  SKUDefultQuestionTBCellText.m
//  ZITHER
//
//  Created by weixin on 2018/8/22.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDefultQuestionTBCellText.h"

@implementation SKUDefultQuestionTBCellText

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self.viewBack setCornerRadiusWithRadius:15 isMasks:YES];
    [self.viewBack setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:1];
    self.backgroundColor = [UIColor redColor];
    [self setMasonry];
}

-(void)setMasonry{
    
    [self.labTakein mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.equalTo(self).offset(24);
        make.height.mas_equalTo(20);
    }];
    
    [self.Cardenter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.right.equalTo(self).offset(-24);
        make.height.width.mas_equalTo(20);
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labTakein.mas_bottom).offset(5);
        make.left.equalTo(self).offset(24);
        make.height.mas_equalTo(20);
    }];
    
    [self.viewText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labTakein.mas_bottom).offset(5);
        make.left.equalTo(self).offset(24);
        make.right.equalTo(self).offset(-24);
    }];
    
    [self.scrollview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.viewText.mas_bottom).offset(5);
        make.left.equalTo(self).offset(24);
        make.right.equalTo(self).offset(-24);
        make.height.mas_equalTo(60);
    }];
    
    [self.viewBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self).offset(-14);
        make.bottom.equalTo(self).offset(-20);
    }];
    
    [self.merchantImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollview.mas_bottom).offset(5);
        make.right.equalTo(self).offset(-24);
        make.height.mas_equalTo(60);
        make.bottom.mas_equalTo(self).offset(-20);
    }];
    
    [self.merchantName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.merchantImage.mas_centerY).offset(5);
        make.right.equalTo(self.merchantImage.mas_left).offset(-5);
    }];
    
    
    
 
}

-(void)setModel:(skuDetailModel *)model{
    _model = model;
    NSString *str = [NSString stringWithFormat:@"%@个接受的报价",self.model.acceptPriceCount];
    self.labTakein.text = str;
    
    if (![self.model.acceptPriceCount isEqualToString:@"0"]) {
        [self setScrImage:self.model.acceptFileList];
        
        [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(60);
        }];
    }else{
        [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
        self.scrollview.hidden = YES;
    }

    [self setNeedsLayout];
}


-(void)setScrImage:(NSArray *)arr{
        self.scrollview.hidden = NO;
        [self.scrollview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        self.scrollview.contentSize = CGSizeMake(arr.count*68+15,0);
        
        for (int j = 0; j<arr.count; j++) {
            UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(j*68+15,0, 60,60)];
            
            [imageV setCornerRadiusWithRadius:5 isMasks:YES];
            imageV.backgroundColor = [UIColor randomColor];
            imageV.contentMode = UIViewContentModeScaleAspectFill;
            
            NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,arr[j]];
            
            [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
            
            [self.scrollview addSubview:imageV];
        }
    
}
@end
